<#--
List of variables to be passed for this template:
        +- rootPackage
        +- applicationName
        +- classNames
        +- directory
        +- Entities: ArrayList of EntityClass.getAsMap()

            |
            +- imports: imports
            |
            +- name: The name of the class.
            |    |
            |    +- single
            |    +- plural
            |
            +- idColumn: the id column
            |    |
            |    +- field
            |    |    |
            |    |    +- name
            |    |    +- type
            |    |
            |    +- getter
            |    +- setter
            |
            +- columns: ArrayList of columns
            |    |
            |    +- field
            |    |    |
            |    |    +- name
            |    |    +- type
            |    |    +- hasTypeParameter
            |    |    +- typeParameter -- only if hasTypeParameter returns true!
            |    +- getter
            |    +- setter

-->

<@pp.dropOutputFile />
<#list Entities as entity>
<@pp.changeOutputFile name="/development/${directory}/GWT/${directory}/client/apis/models/${entity.name.single}.java" />

package ${rootPackage}.${applicationName}.client.apis.models;
<#list entity.imports as import>
import ${import};
</#list>
    <#list entity.columns as column>
        <#if column.field.hasTypeParameter >
            <#list classNames as name>
                <#assign foundTypeParameter = false >
                <#if name.single == column.field.typeParameter >
                    <#assign foundTypeParameter = true >
                    <#assign name = name.plural >
                    <#break>
                </#if>
            </#list>
            <#if foundTypeParameter >
import ${rootPackage}.${applicationName}.client.apis.utils.JavaScriptArray;
                <#break>
            </#if>
        </#if>
    </#list>
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.json.client.JSONObject;

public class ${entity.name.single} extends JavaScriptObject {
	protected ${entity.name.single}() {
	}

	public final native ${entity.idColumn.field.type} ${entity.idColumn.getter}() /*-{
		return this.${entity.idColumn.field.name};
	}-*/;
<#--
        <#list entity.columns as column>
	public final native ${column.field.type} ${column.getter}() /*-{
		return this.${column.field.name};
	}-*/;

	public final native void ${column.setter}(${column.field.type} ${column.field.name}) /*-{
		this.${column.field.name} = ${column.field.name};
	}-*/;
        </#list>
-->

    <#list entity.columns as column>
        <#if column.field.hasTypeParameter >
            <#list classNames as name>
                <#assign foundTypeParameter = false >
                <#if name.single == column.field.typeParameter >
                    <#assign foundTypeParameter = true >
                    <#assign name = name.plural >
                    <#break>
                </#if>
            </#list>
            <#if foundTypeParameter >
    /**
     * Getter for ${column.field.name}.
     *
     * @return value for ${column.field.name}
     */
	public final native JavaScriptArray<${column.field.typeParameter}> ${column.getter}() /*-{
		return this.${column.field.name};
	}-*/;

    /**
     * Setter for ${column.field.name}.
     *
     * @param value the value to set
     */
        public final native void ${column.setter}(JavaScriptArray<${column.field.typeParameter}> ${column.field.name}) /*-{
		this.${column.field.name} = ${column.field.name};
	}-*/;
            </#if>
        <#else>
    /**
     * Getter for ${column.field.name}.
     *
     * @return value for ${column.field.name}
     */
	public final native ${column.field.type} ${column.getter}() /*-{
		return this.${column.field.name};
	}-*/;

    /**
     * Setter for ${column.field.name}.
     *
     * @param value the value to set
     */
	public final native void ${column.setter}(${column.field.type} ${column.field.name}) /*-{
		this.${column.field.name} = ${column.field.name};
	}-*/;
        </#if>
    </#list>

	public final JSONObject getJSONObject()
	{
		return new JSONObject(this);
	}
}
</#list>
